#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<cstdio>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<math.h>
#include<set>
#include<functional>
#include <bitset>
using namespace std;
using ull = unsigned long long;
using i128 = __int128_t;
//inline int inc(int x,int v,int mod){x+=v;return x>=mod?x-mod:x;}//代替取模+
#define endl '\n'
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
#define int long long

const int N = 1e5+10;


int e[N * 2],ne[N * 2],idx,h[N];
vector<int>arr(N);

void add(int a,int b)
{
    e[idx] = b;
    ne[idx] = h[a];
    h[a] = idx ++;
}

int fa[100010][25];
bitset<25> bs[N][25];
int depth[N];

void dfs (int x, int fas)
{
	depth[x] = depth[fas] + 1;
	fa[x][0] = fas;
	bs[x][0].set (arr[x], 1);
	for(int i = 1; i <= 20; i++) {
		fa[x][i] = fa[fa[x][i - 1]][i - 1];
		bs[x][i] = bs[x][i - 1] | bs[fa[x][i - 1]][i - 1];
	}
    for(int i = h[x]; i != -1; i = ne[i])
    {
        int j = e[i];
        if(j == fas) continue;
        dfs(j,x);
    }
}
int lca(int a,int b)
{
    bitset <25> ans,b1,b2;
    if(depth[a] < depth[b]) swap(a,b);
    for(int k = 22; k >= 0; k --)
    {
        if(depth[fa[a][k]] >= depth[b])
        {
            ans = ans | bs[a][k];
            a = fa[a][k];
        }
    }
    if(a == b) 
    {
        ans = ans | bs[a][0];
        return ans.count();
    }
    for(int k = 22; k >= 0; k --)
    {
        if(fa[a][k] != fa[b][k])
        {
            ans = ans | bs[a][k];
            ans = ans | bs[b][k];
            a = fa[a][k];
            b = fa[b][k];
        }
    }
    ans = ans | bs[a][0];
    ans = ans | bs[b][0];
    ans[arr[fa[a][0]]] = 1;
    return ans.count();
}


void solve()
{  
    memset(h,-1,sizeof h);
    int n,q;
    cin >> n >> q;
    for(int i = 1; i <= n; i ++) cin >> arr[i];

    for(int i = 1; i <= n - 1; i ++)
    {
        int a,b;
        cin >> a >> b;
        add(a,b);
        add(b,a);
    }
    dfs(1,0);
    while(q--)
    {
        int a,b;
        cin >> a >> b;
        cout << lca(a,b) << endl;
    }
}
signed main()
{
    int t = 1;
    //cin >> t;
    while(t --)
    {
        solve();
    }
}
